<?php
include_once("../configs/admin.config.inc.php");//--> admin global var
include_once("db.inc.php");						//--> db global var
include_once("Operation.php");					//--> Operation
include_once("Pic.php");						//--> Pic
include_once("InfoClass.php");					//--> InfoClass
require_once("controlHeader.php");				//--> system control header

$objOperate		= new Operation($objSession->session['lan']);			//--> Operation instance
$objPic			= new Pic($objSession->session['lan'], $uid);			//--> Pic 
$objInfoClass	= new InfoClass($objSession->session['lan'], $uid);	//--> InfoClass

$arrOperate = $objOperate->arrGetFromGroupIDAndMenuID($gid, $menuid);

if(isset($_GET['id']) && !empty($_GET['id'])){
	$id 		= $_GET['id'];

	$arrDataInfo = $objPic->getFromID($arrOperate, $id);
	
	$isReturn = $objPic->delete($arrOperate, $id);
	if($isReturn){
		$arrDataInfo = $objInfoClass->getFromID($arrOperate, $arrDataInfo['formatid']);
		if(is_array($arrDataInfo)){
			$filepath = PIC_DOWNLOAD_DIR . $id . '.' . $arrDataInfo['name'];
			if(file_exists($filepath))
				unlink($filepath);
		}
		
		$error_message = 'delete successfully.';
	}else 
		$error_message = 'delete failure.';
}


echo "<script language='javascript'>";
echo "alert(\"$error_message\");";
echo "location.href=\"".$_SERVER['HTTP_REFERER']."\";";
echo "</script>";

//$backurl = $_SERVER['HTTP_REFERER'];
//header("Location: $backurl");
?>
